package com.codeoss.framework.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.codeoss.framework.context.YunContext;
import com.codeoss.framework.request.ViewRequest;
import com.codeoss.framework.response.ViewResponse;
import com.codeoss.framework.service.IViewService;

@Controller
@RequestMapping("view")
public class ViewController {
	@Autowired
	private IViewService viewService;
	
	@RequestMapping(value = "initPage", method = RequestMethod.GET)
	@ResponseBody
	public ViewResponse initPage(@RequestParam("_code") String code,@RequestParam Map<String,String> queryMap){
		YunContext yunContext=YunContext.getCurrentContext();
		yunContext.setQueryMap(queryMap);
		ViewResponse viewResponse=viewService.initPage(yunContext,code);
		return viewResponse;
	}
	
	@RequestMapping(value = "processRequest", method = RequestMethod.POST)
	@ResponseBody
	public ViewResponse processRequest(@RequestParam("_code") String code,@RequestBody ViewRequest viewRequest){
		YunContext yunContext=YunContext.getCurrentContext();
		yunContext.setViewRequest(viewRequest);
		ViewResponse viewResponse=viewService.processRequest(yunContext,code);
		return viewResponse;
	}
}
